package com.setting.service;

import java.util.ArrayList;
import java.util.List;

import javax.transaction.Transactional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.entity.Sysdic;
import com.interfaces.SysdicDao;

import com.utils.JsonResult;
import com.utils.JsonSysdic;

/**
 * @Title: SysdicService.java
 * @Package com.service
 * @author 孙梦楠
 * @date 2017年7月27日 上午8:55:59
 * @version V1.0.0
 */

@Service
public class SysdicService {

	@Autowired
	private SysdicDao sysdicdao;

	private static final Logger log = LoggerFactory.getLogger(SysdicService.class);

	// 字典接口
	@Transactional
	public JsonResult<List<JsonSysdic>> listsysdic(String sysdictype, Integer state, String Message,
			String languagecookie) {
			log.info("Sysdic  "+sysdictype);
		List<Sysdic> sysdics = sysdicdao.findBySysdictype(sysdictype);
		List<JsonSysdic> jsonsysdics = new ArrayList<JsonSysdic>();

		if (sysdics.size() != 0) {
			
			for (int i = 0; i < sysdics.size(); i++) {

				Sysdic sysdic = sysdics.get(i);
				JsonSysdic jsonsysdic = new JsonSysdic();
				jsonsysdic.setSysdicvalue(sysdic.getSysdicvalue());
				// 多语言输出显示
				if (languagecookie.equals("cn")) {
					jsonsysdic.setSysdicname(sysdic.getSysdicdisplay());
				} else if (languagecookie.equals("en")) {
					jsonsysdic.setSysdicname(sysdic.getSysdicdisplay_e());

				}
				jsonsysdics.add(jsonsysdic);
			}
		}

		return new JsonResult<List<JsonSysdic>>(state, Message, jsonsysdics);
	}

	// 操作员 设备类型分类
	@Transactional
	public String gettype(String opetypecookie, String equipmenttype) {

		String type = sysdicdao.findBySysdictypeAndSysdicvalue("100" + opetypecookie, equipmenttype).getSysdicdisplay();

		return type;
	}

	// 查询字典实际含义
	public String finddisplay(String sysdictype, String sysdicvalue, String languagecookie) {
		
		String sysdicdispaly = null;
		if (languagecookie.equals("cn")) {
			sysdicdispaly = sysdicdao.findBySysdictypeAndSysdicvalue(sysdictype, sysdicvalue).getSysdicdisplay();
		} else if (languagecookie.equals("en")) {
			sysdicdispaly = sysdicdao.findBySysdictypeAndSysdicvalue(sysdictype, sysdicvalue).getSysdicdisplay_e();

		}
		return sysdicdispaly;
	}
	
	

}
